package connectUtil;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ConnectionUtil {
	private static Connection conn;
	
	public static Connection getConnection() {
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection("jdbc:sqlserver://FWA-LAB1-PC21\\SQLEXPRESS;database=ATJB", "sa", "12345678");
			System.out.println(" Connected ! ");
		} catch (Exception ex) {
            System.out.println(" Connect fail ! "+ex.getMessage());
		}
		return conn;
	}
		
	// Close connections
	public static void closeConnections(Connection conn, CallableStatement callProc, ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (callProc != null) {
				callProc.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException sqlex) {
			
		}
	}
}
